<script setup>
import { reactive, ref } from 'vue'
import { useStore } from 'vuex'
const editMyInfo = ref(false)
const dialogFormVisible = ref(false)
const formLabelWidth = '100px'

const form = reactive({
  oldPassword: '',
  newPassword1: '',
  newPassword2: ''
})

const userinfo = useStore().getters.getUser
const username = userinfo.username
const email = userinfo.email
const sex = userinfo.sex
const age = userinfo.age
const userType = userinfo.userType

</script>

<template>
  <el-tab-pane class="test">
    <template #label>
      <span class="tab-item">我的信息</span>
    </template>
    <div class="content-container">
        <el-descriptions
          title="我的信息"
          direction="vertical"
          :column="4"
          border
        >
          <el-descriptions-item label="用户名">{{ username }}</el-descriptions-item>
          <el-descriptions-item label="邮箱">{{ email }}</el-descriptions-item>
          <el-descriptions-item label="性别" :span="2">{{ sex }}</el-descriptions-item>
          <el-descriptions-item label="年龄">{{ age }}</el-descriptions-item>
          <el-descriptions-item label="用户类型">{{ userType }}</el-descriptions-item>
        </el-descriptions>

      <el-row class="mb-4">
        <el-button type="primary" @click="dialogFormVisible = true" round>修改密码</el-button>
        <el-button type="primary" @click="editMyInfo = true" round>修改我的信息</el-button>
      </el-row>

      <el-dialog v-model="dialogFormVisible" title="修改密码">
        <el-form :model="form">
          <el-form-item label="旧密码" :label-width="formLabelWidth">
            <el-input v-model="form.oldPassword" autocomplete="off" />
          </el-form-item>
          <el-form-item label="新密码" :label-width="formLabelWidth">
            <el-input v-model="form.newPassword1" autocomplete="off" />
          </el-form-item>
          <el-form-item label="确认密码" :label-width="formLabelWidth">
            <el-input v-model="form.newPassword2" autocomplete="off" />
          </el-form-item>
        </el-form>
        <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取消</el-button>
        <el-button type="primary" @click="dialogFormVisible = false">
          提交
        </el-button>
      </span>
        </template>
      </el-dialog>
    </div>
  </el-tab-pane>

  <el-dialog v-model="editMyInfo" title="修改个人信息">
    <el-form :model="form">
      <el-form-item label="用户名" :label-width="formLabelWidth">
        <el-input v-model="form.username" autocomplete="off" placeholder="请输入用户名"/>
      </el-form-item>
      <el-form-item label="邮箱" :label-width="formLabelWidth">
        <el-input v-model="form.email" autocomplete="off" placeholder="请输入邮箱"/>
      </el-form-item>
      <el-form-item label="年龄" :label-width="formLabelWidth">
        <el-input v-model="form.age" autocomplete="off" placeholder="请输入年龄"/>
      </el-form-item>
      <el-form-item label="性别" :label-width="formLabelWidth">
        <el-select v-model="form.sex" placeholder="请选择性别">
          <el-option label="男" value="1" />
          <el-option label="女" value="2" />
          <el-option label="未知" value="3" />
        </el-select>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="editMyInfo = false">取消</el-button>
        <el-button type="primary" @click="editMyInfo = false">
          修改
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>

<style scoped>
.content-container{
  text-align: left;
  margin-left: 20px;
}

.dialog-footer button:first-child {
  margin-right: 20px;
}
</style>
